//
//  ItemView.m
//  HCNewGoldFinger
//
//  Created by zjhcsoft on 16/6/1.
//  Copyright © 2016年 zjhcsoftios. All rights reserved.
//

#import "ItemView.h"
#import "shuliangmodel.h"
#import "NetworkAddress.h"



@implementation ItemView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    
    if (self) {
        [self createSubview];
    }
    return self;
}


-(void)createSubview{
    CGRect frame = self.bounds;
    CGFloat width = 30 * kScreenWidth / 320;
    CGFloat height = 30 * kScreenWidth / 320;
    CGFloat xPadding = (frame.size.width - 35)/2;
    _imageView = [[UIImageView alloc] initWithFrame:CGRectMake(xPadding, 20 * frame.size.height / 96 , width, height)];
//    [_imageView setImage:[UIImage imageNamed:@"gongdan"]];
    [self addSubview:_imageView];

    _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, height + 20 * frame.size.height / 96 + 7, frame.size.width-20, 15)];
//    [_titleLabel setText:@"工单"];
    [_titleLabel setTextAlignment:NSTextAlignmentCenter];
    [_titleLabel setFont:[UIFont systemFontOfSize:14]];
    [self addSubview:_titleLabel];
    
    _badgeLabel = [[UILabel alloc] initWithFrame:CGRectMake(xPadding + width,  5 ,20, 15)];
    [_badgeLabel setTextColor:[UIColor whiteColor]];
    [_badgeLabel setTextAlignment:NSTextAlignmentCenter];
    [_badgeLabel setFont:[UIFont systemFontOfSize:9]];
    _badgeLabel.layer.cornerRadius = 4;
    _badgeLabel.layer.masksToBounds = YES;
    _badgeLabel.adjustsFontSizeToFitWidth = YES;
    [self addSubview:_badgeLabel];
    if (frame.size.height < 60) {
        [_imageView setFrame:CGRectMake(xPadding, 13, 25 , 25)];
        [_badgeLabel setFrame:CGRectMake(xPadding + 20,  1 ,20, 12)];
        [_titleLabel setFrame:CGRectMake(0, 40, frame.size.width- 15, 15)];

    }
}
-(void)setModel:(HomeWorkListModel *)model{
      _model = model;
    
    
    if (![_titleLabel.text isEqualToString:model.name]) {
        _titleLabel.text =model.name;
        
        _imageView.image = [UIImage imageNamed:model.imagename];
    }
   }


-(void)setArr:(NSMutableArray *)arr{
    
    for (NSMutableDictionary *dic in arr) {
        shuliangmodel *model =[[shuliangmodel alloc] init];
        [model setValuesForKeysWithDictionary:dic];
        
        
        if (model.logId ==_model.logId) {
            //
            //
            _badgeLabel.backgroundColor =[UIColor redColor];
            if (model.total >99) {
                _badgeLabel.text =@"99+";
            }else{
                _badgeLabel.text =[NSString stringWithFormat:@"%ld",(long)model.total];
            }
            //
            if ([ _badgeLabel.text isEqualToString:@"0"]) {
                _badgeLabel.text =nil;
                _badgeLabel.backgroundColor = [UIColor clearColor];
            }
        }
    }
 
    
    
    
}






@end
